Page({
  data: {
    users: [
      { id: 1, name: "牛马1" },
      { id: 2, name: "牛马2" },
      { id: 3, name: "牛马3" },
      { id: 4, name: "牛马4" },
      { id: 5, name: "牛马5" },
      { id: 6, name: "牛马6" },
      { id: 7, name: "牛马7" },
      { id: 8, name: "牛马8" },
      { id: 9, name: "牛马9" },
      { id: 10, name: "牛马10" },
      { id: 11, name: "牛马11" },
      { id: 12, name: "牛马12" },
      { id: 13, name: "牛马13" },
      { id: 14, name: "牛马14" },
      { id: 15, name: "牛马15" },
      { id: 16, name: "牛马16" },
      { id: 17, name: "牛马17" }
      // ... 其余数据
    ],
    editMode: [],
  },

  onLoad: function () {
    const storedNames = wx.getStorageSync('userNames') || {};
    this.setData({
      users: this.data.users.map(user => ({
        ...user,
        name: storedNames[user.id] || user.name
      }))
    });
  },

  onNameInput: function (event) {
    const id = event.currentTarget.dataset.id;
    const newName = event.detail.value;
    
    this.setData({
      users: this.data.users.map(user =>
        user.id === id ? { ...user, name: newName } : user
      )
    });

    // 持久化更新
    const storedNames = wx.getStorageSync('userNames') || {};
    storedNames[id] = newName;
    wx.setStorageSync('userNames', storedNames);
  }
});
